home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: How to copy an object?
- Date: 29 Feb 1996 14:20:43 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4h4cnr$kd@dawn.mmm.com>
- References: <4h05rb$su6@atlas.tncnet.com>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Simon Lee (SimonLee) wrote:
-
- > Hello,
-
- > I'm trying to have a member function return a duplicate copy of a
- > member data object. How would I go about this?
-
- > Ie.
-
- > class x {
- > private:
- > Y *object_of_class_y;
-
- > public:
- > Y GetY();
- > };
-
-
- > I would like GetY() to return a copy of object_of_class_y, not a pointer
- > to it.
-
- This should do it:
-
- Y x::GetY() { return *object_of_class_y; }
-
- > Any email responses appreciated.
-
- People read your article because it looked interesting. They deserve
- to read the answers too.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-